search.parse();

var file = $("#file");
var filename = search.get("filename");
file.change(onFileChange);
filename._textboxhtml.dblclick(onFilepathDblClick);

function onFileChange(e) {
	var file = e.currentTarget.files[0];
	if (!/^.+\.txt$/.test(file.name)) {
		SearchUtils.msg("不支持的文件类型");
		return;
	}
	
	filename.setValue(file.name);
}

function onFilepathDblClick(e) {
	file.click();
}

function onConfirmClick() {
	search.manualShowLoading();
	
	var form = new FormData();
	form.append("file", file[0].files[0]);
	
	$.ajax({
		url : __ctx + "/areas/importAreas.xhtml", 
		data : form, 
		timeout : 600000, 
		contentType : false, 
		processData : false, 
		success : function(data, status) {
			search.manualCloseLoading();
			
			if (data.status) {
				top.search.info({content : data.result.message, funl : function() {
					if (data.result.success > 0) window.closeWindow("ok");
					else window.closeWindow("cancel");
				}});
			} else {
				resetForm();
				SearchUtils.msg(response.result);
			}
		}, 
		error : function(xhr, msg, e) {
			search.manualCloseLoading();
			
			resetForm();
			SearchUtils.msg("网络请求错误！");
		}
	});
}

function resetForm() {
	file.val(null);
	filename.setValue(null);
}